from django.db import models

# Create your models here.
from django.db import models
class School(models.Model):
    id = models.AutoField(primary_key=True)
    number = models.IntegerField(verbose_name='序号',unique=True)
    name = models.CharField(verbose_name='名称', max_length=50,unique=True)
    site = models.CharField(verbose_name='地址', max_length=50)
    linkman = models.CharField(verbose_name='联系人', max_length=50)
    phone = models.CharField(verbose_name='联系电话', max_length=80)
    create_timestamp = models.DateTimeField(verbose_name='创建时间', auto_now_add=True)
    last_edit = models.DateTimeField(verbose_name='更新时间',auto_now=True)
    class Meta:
        unique_together = (("number", "name"),)
        ordering = ['number']
        verbose_name = '信息'
        verbose_name_plural = '信息'
    def __str__(self):
        return  self.name

class XYW_IP(models.Model):
    XYW_IP = models.CharField(verbose_name='网段',max_length=50,null=True)
    XYW_gateway = models.CharField(verbose_name='网关', max_length=50,null=True)
    XYW_pw = models.CharField(verbose_name='设备密码', max_length=50, null=True,blank = True)
    XYW_SBCJ = models.CharField(verbose_name='设备厂家', choices=(('RG', '锐捷'), ('CISCO', '思科'), ('HW', '华为'),('H3C', '华三')),max_length=50, null=True,blank = True)
    XYW_SBXH = models.CharField(verbose_name='设备型号', max_length=50, null=True,blank = True)
    last_edit = models.DateTimeField(verbose_name='更新时间', auto_now=True)
    name2=models.OneToOneField(verbose_name='学校名称',to=School,on_delete=models.CASCADE)

    def dis_num(self):
        return self.name2.number
    dis_num.short_description = '序号'
    class Meta:
        verbose_name = '校园网IP'
        verbose_name_plural = '校园网IP'
        ordering = ['id']


    def __str__(self):
        return self.XYW_IP
